/**
 * udes.ds.agent.hw
 * TestingEquation.java
 * 7 oct. 09
 */
package ift605.tp3.utils.potentialyuseless;

import ift605.tp3.utils.equations.AbstractEq;
import ift605.tp3.utils.equations.IEquation;
import ift605.tp3.utils.equations.MultiplicativeEq;
import ift605.tp3.utils.equations.PowEq;
import ift605.tp3.utils.equations.SummativeEq;

import java.math.BigDecimal;

/**
 * @author Luc Bergevin
 * @version 1.0
 */
public class TestingEquation extends AbstractEq
{
    
    public class ExponentialEquation extends AbstractEq
    {
        
        private static final long serialVersionUID = 1L;
        private final double __exponent;
        
        /**
         * Equation of the type E^x
         * 
         * @param _exponent
         *            the exponent for E
         */
        public ExponentialEquation(double exponent)
        {
            super();
            __exponent = exponent;
        }
        
        /**
         * @see udes.ds.agent.AbstractEquation#getUserReadableString()
         */
        @Override
        public String getUserReadableString()
        {
            return new String("E^" + Double.toString(__exponent));
        }
        
        /**
         * @see udes.ds.agent.Equation#getFunctionValue(double)
         */
        public double getFunctionValue(double x)
        {
            return Math.exp(x);
        }
        
        @Override
        public BigDecimal eval(BigDecimal x)
        {
            return BigDecimal.valueOf(getFunctionValue(x.doubleValue()));
        }
        
    }
    
    private static final long serialVersionUID = 1L;
    private final SummativeEq _equation;
    
    /**
     * Construct an Equation to test the agent system.
     */
    public TestingEquation()
    {
        final PowEq basic1 = new PowEq(4.0, 2);
        final PowEq basic2 = new PowEq(8.0, 3);
        final SummativeEq sum1 = new SummativeEq(basic1, basic2);
        
        final PowEq basic3 = new PowEq(5.0, 8);
        final ExponentialEquation expo1 = new ExponentialEquation(13);
        final SummativeEq sum2 = new SummativeEq(basic3, expo1);
        
        final MultiplicativeEq mult1 = new MultiplicativeEq(expo1, sum1);
        final MultiplicativeEq mult2 = new MultiplicativeEq(basic2, sum2);
        
        _equation = new SummativeEq(mult1, mult2);
        
    }
    
    /**
     * @see udes.ds.agent.Equation#getFunctionValue(double)
     */
    public double getFunctionValue(double x)
    {
        return _equation.getFunctionValue(x);
    }
    
    /**
     * @see udes.ds.agent.Equation#getUserReadableString()
     */
    @Override
    public String getUserReadableString()
    {
        return _equation.getUserReadableString();
    }
    
    public IEquation getEquation()
    {
        return _equation;
    }
    
    @Override
    public BigDecimal eval(BigDecimal x)
    {
        return _equation.eval(x);
    }
    
}
